package com.fau.cm.action.index;

import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.fau.cm.action.PublicAction;
import com.fau.cm.entity.MedicalAdmin;
import com.fau.cm.entity.MedicalCallCustomerHealth;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 客户健康档案Action  
 * @author kangyj
 * @datetime 2014年12月7日,上午11:33:02
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class CustomerHealthAction extends PublicAction implements
		ModelDriven<MedicalCallCustomerHealth> {

	private static final long serialVersionUID = -6155128776617910701L;
	
	private MedicalCallCustomerHealth customerHealth = new MedicalCallCustomerHealth();
	
	/**
	 * @desc 客户健康档案页面初始化
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月7日,上午11:34:58
	 */
	@Action(value = "customer_health_init", results = {@Result(location = "customer_health_init.jsp")})
	private String init() {
		return SUCCESS;
	}
	
	/**
	 * @desc 查询客户健康档案
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月7日,上午11:35:37
	 */
	@Action(value = "customer_health_view")
	public String view() {
		HttpServletResponse response = ServletActionContext.getResponse();
		list = this.baseAllService.getCustomerService().customerHealthView(customerHealth.getCustomerId());
		formatJSON(response, list);
		return null;
	}
	
	/**
	 * @desc 保存客户健康档案
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月7日,下午12:16:44
	 */
	@Action(value = "customer_health_save")
	public String save() {
		HttpServletResponse response = ServletActionContext.getResponse();
		MedicalAdmin admin = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		map = new HashMap<String, Object>();
		customerHealth.setAttendantId(admin.getId());
		this.baseAllService.getCustomerService().saveCustomerHealth(customerHealth);
		map.put("success", true);
		formatJSON(response, map);
		return null;
	}
	
	/**
	 * @desc 删除客户健康档案
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月7日,下午12:17:56
	 */
	@Action(value = "customer_health_del")
	public String del() {
		HttpServletResponse response = ServletActionContext.getResponse();
		map = new HashMap<String, Object>();
		if(StringUtils.isNotBlank(customerHealth.getId())) {
			this.baseAllService.getCustomerService().delCustomerHealth(customerHealth);
			map.put("success", true);
		} else {
			map.put("success", false);
		}
		formatJSON(response, map);
		return null;
	}
	
	/**
	 * @desc 跳转到选择健康症状页面
	 * @return
	 * @author kangyj
	 * @datetime 2014年12月7日,下午12:35:57
	 */
	@Action(value = "customer_health_choose", results = {@Result(location = "customer_health_choose.jsp")})
	public String choose() {
		return SUCCESS;
	}

	@Override
	public MedicalCallCustomerHealth getModel() {
		return customerHealth;
	}

}
